# encoding: utf-8

import cx_Oracle
import sys

if len(sys.argv) < 4:
    print "more var is needed"
else:
    db = cx_Oracle.connect('cdwbase', 'cdwbase', 'CDWtest')
    print db.version

    sql = r"select max(day_dt) from cdwAnalyse.T00_day_def where day_dt<to_date(:arg1,'yyyy-mm-dd')"
    cursor = db.cursor()
    cursor.execute(sql, {"arg1":"2015-04-04"})
    row = cursor.fetchall()
    print row[0][0].strftime("%Y-%m-%d")
    cursor.close()
    db.close()